close all;
clear all;

load avecountsppm;
%dataext has all the data for all the scans in a 5x5 cell array.
%dataext{kk,ii}(:,:,jj)
%kk: anneal # in following order

%preanneal (3.8 mW od2) [no data or notes for single NV or excitation power; Using settings from 980 150hr]
%980 150h, 3.8 mW od3 confirmed
%1000 150h, 2.2 mW od3 confirmed
%150 150 h, 2 mW? od2 confirmed
%150 150h second time, 2 mW od2 confirmed

%ii: position
%jj: depth (starting from the top surface, 10 micron steps)
%50 x 50 micron scan
%for each set, I need an intensity to NV count calibration

%avecountsppm has the average counts over each of the kk,ii,jj images above

%the following need to be updated!!!!
countsperNV = [2.95 2.95 1.16 1.05 0.9438]*10^4;
excitationvolume = [42.035 42.035 26.266 26.269 20.13]; %needs to be in um^3
ndfactor = [100 1000 1000 100 100];  

%conversion between um^3 
conv = 1/175827*1000; %number of atoms in ppb in cubic micron

%create and plot normalized data for each location
depth = (0:100)*2.4;
annealnum = [0 12 13 14 15]; %doesn't work as a label- need to fix afterwards
for ii = 1:5   %for each position
    for kk = 1:5
    dataarray(kk, ii, :) = avecounts{kk,ii};
    densityarray(kk,ii,:) = dataarray(kk, ii, :)/...
        (countsperNV(kk)*excitationvolume(kk))*conv*ndfactor(kk);
    end
%     subplot(2,3, ii)
    
%     imagesc(annealnum, depth, squeeze(densityarray(:,ii,:))');
%     axis square;
%     colorbar;
%     title(['spot ' num2str(ii)]);
%    set(gca,'FontName','Palatino','FontSize',20);
end

figure
 avedensityarray = mean(densityarray, 2);
 imagesc(annealnum, depth, squeeze(avedensityarray)');
 colorbar;
 set(gca,'FontName','Palatino','FontSize',20);
 
%Plot slice at 100*2.4 um
figure
%plot(1:5,squeeze(avedensityarray(:,11)),'-o');
avedensityarray = squeeze(avedensityarray);

for ii=1:5
    plot(1:11,avedensityarray(ii,:)); hold on
end

%  figure
%  avedataarray = mean(dataarray, 2);
%  imagesc(annealnum, depth, squeeze(avedataarray)');
%  colorbar;
%  set(gca,'FontName','Palatino','FontSize',20);
%  title('Raw Data')



